var app = getApp()
const api = require('../../utils/utils')
Page({
  data: {
    iconUrl: api.iconUrl,
    // 登录状态
    userinfo: {},
    isLogin: false,
    // 导航数据
    list: [{
        pagePath: "/pages/index/index",
        text: "首页",
        iconPath: api.iconUrl + "home.png",
        selectedIconPath: api.iconUrl + "home-filling.png"
      },
      {
        pagePath: "/pages/my/my",
        text: "我的",
        iconPath: api.iconUrl + "user.png",
        selectedIconPath: api.iconUrl + "user-filling.png"
      }
    ],
  },
  onShow: function () {
    this.setData({
      isLogin:app.globalData.isLogin
    })
    if (app.globalData.isLogin) {
      // 查询当前登录用户基本信息
      api.request('get', '/user').then((res) => {
        this.setData({
          userinfo: res
        })
      })
    }
  },
  // 退出登录确认框
  show_logout() {
    const dialog = this.selectComponent("#logout_dialog")
    dialog.linShow({
      title: "退出登录？",
      type: "confirm"
    })
  },
  // 退出登录
  logout() {
    wx.removeStorage({
      key: 'token',
      success(res) {
        wx.navigateTo({
          url: '/pages/login/login',
        })
      }
    })
    app.globalData.isLogin = false
  },
  // 跳转到登录页面
  toLogin() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  // 跳转到注册页面
  toEnroll() {
    wx.navigateTo({
      url: '/pages/enroll/enroll',
    })
  },
})